package com.aqs;

import java.util.concurrent.CountDownLatch;

/**
 * @author Zhang Zhe
 * @since 2020年02月19日 07:42:00
 */
public class CountdownLatchTest {

    private static Integer m = 0;
	private static CountDownLatch latch = new CountDownLatch(10);

	public static void main(String[] args) {

		Thread[] threads = new Thread[10];

		for (int i = 0; i < threads.length ; i++) {
			threads[i] = new Thread(()->{
				System.out.println(m++);
				try {
					Thread.sleep(100);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				latch.countDown();
			});
		}

		for (int i = 0; i <threads.length ; i++) {
			threads[i].start();
		}
		try {
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("m:"+m);
	}

}
